package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @auther zzyy
 * @create 2022-09-02 19:52
 */
@RestController
@Slf4j
public class RedisController
{
    @Resource
    private RedisTemplate redisTemplate;

    @PostMapping (value = "/redis/add")
    public void add()
    {
        redisTemplate.opsForValue().set("k2","redis测试"+new Random().nextInt(100)+1);
        System.out.println ("Ok");
    }

    @RequestMapping(value = "/redis/{key}", method = RequestMethod.GET)
    public String getById(@PathVariable String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

}


